package com.leetcode.partition4;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

/**
 * @author `RKC`
 * @date 2022/2/17 10:19
 */
public class LC327区间和的个数_线段树 {

    private static final int N = 300010;
    private static Node[] tr = new Node[N << 2];
    private static long[] sum = new long[N];
    private static Set<Long> set = new TreeSet<>();
    private static Map<Long, Integer> map = new HashMap<>();
    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), lower = Integer.parseInt(ss[1]), upper = Integer.parseInt(ss[2]);
        int[] nums = new int[n];
        ss = reader.readLine().split(" ");
        for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(ss[i]);
        writer.write(countRangeSum(nums, lower, upper) + "\n");
        writer.flush();
    }

    public static int countRangeSum(int[] nums, int lower, int upper) {
        n = nums.length;
        for (int i = 1; i <= n; i++) sum[i] += sum[i - 1] + nums[i - 1];
        //对前缀和进行有序离散化
        for (int i = 0; i <= n; i++) {
            set.add(sum[i]);
            set.add(sum[i] - lower);
            set.add(sum[i] - upper);
        }
        int idx = 0, ans = 0;
        for (long s : set) map.put(s, ++idx);
        //创建线段树
        build(1, 1, map.size());
        for (int i = 0; i <= n; i++) {
            long s = sum[i];
            //找到左区间和右区间，通过线段树计算当前区间满足条件的数量
            int l = map.get(s - upper), r = map.get(s - lower), pos = map.get(s);
            ans += query(1, l, r);
            modify(1, pos, pos, 1);
        }
        return ans;
    }

    private static int query(int u, int l, int r) {
        if (l <= tr[u].l && r >= tr[u].r) {
            return tr[u].val;
        }
        pushdown(u);
        int mid = tr[u].l + tr[u].r >> 1, res = 0;
        if (l <= mid) res = query(u << 1, l, r);
        if (r > mid) res += query(u << 1 | 1, l, r);
        return res;
    }

    private static void modify(int u, int l, int r, int val) {
        if (l <= tr[u].l && r >= tr[u].r) {
            tr[u].val += val;
            tr[u].add = val;
        } else {
            pushdown(u);
            int mid = tr[u].l + tr[u].r >> 1;
            if (l <= mid) modify(u << 1, l, r, val);
            if (r > mid) modify(u << 1 | 1, l, r, val);
            pushup(u);
        }
    }

    private static void pushdown(int u) {
        //本题是单点修改，区间查询，其实是不需要pushdown来下传懒标记的
        if (tr[u].add != 0) {
            tr[u << 1].val += tr[u].add;
            tr[u << 1].add += tr[u].add;
            tr[u << 1 | 1].val += tr[u].add;
            tr[u << 1 | 1].val += tr[u].add;
            tr[u].add = 0;
        }
    }

    private static void pushup(int u) {
        tr[u].val = tr[u << 1].val + tr[u << 1 | 1].val;
    }

    private static void build(int u, int l, int r) {
        tr[u] = new Node(l, r);
        if (l != r) {
            int mid = l + r >> 1;
            build(u << 1, l, mid);
            build(u << 1 | 1, mid + 1, r);
            pushup(u);
        }
    }

    private static class Node {
        private int l, r;
        private int val, add;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
        }

        public Node(int l, int r, int val, int add) {
            this.l = l;
            this.r = r;
            this.val = val;
            this.add = add;
        }
    }
}
